﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DC2010.Objects;
using DC2010;
using DC2010.Objects.Data;

namespace DC2010_Editor.Controls.Utils
{
    public partial class PartyInfoForm : Form
    {
        public PartyInfo data { get; set; }

        public PartyInfoForm()
        {
            InitializeComponent();
        }

        public PartyInfoForm(PartyInfo p) : this()
        {
            data = p; 
        }

        private void PartyInfoForm_Load(object sender, EventArgs e)
        {
            if (data != null)
            {
                EffectIdTextBox.Text = data.Id;
                if (data.Loc != null)
                {
                    textBox2.Text = data.Info.Loc.Floor;

                    numericUpDown1.Value = (decimal)data.Info.Loc.X;
                    numericUpDown2.Value = (decimal)data.Info.Loc.Y;
                }

                seTextBox3.SetRelatedObject(data.Info.Effects, EffectType.Pump);
                scTextBox1.SetRelatedObject(data.Info.Conditions);
                
                Tile t = data.FindOwner();
                if (t != null)
                {
                    textBox1.Text = t.Info.Id;
                }


                foreach (Creature c in data.Info.MembersBrowsable.Values)
                {
                    if (c.Info.PartyId == data.Info.Id)
                    {
                        richTextBox1.AppendText(c.Info.Id+@"\n");
                    }
                }
            }
        }

        private void SaveFloorButton_Click(object sender, EventArgs e)
        {
            if (data.Info.Loc == null) data.Info.Loc = new DungeonLoc();
            data.Info.Loc.X = (int)numericUpDown1.Value;
            data.Info.Loc.Y = (int)numericUpDown2.Value;
            data.Info.Loc.Floor = textBox2.Text;
            data.Info.Loc.Facing = Directions.North;

            Root.I.PartySystem.Save();
            Root.I.PartySystem.SaveInstance();

            Close();
        }
    }
}
